﻿// This source is subject to Microsoft Public License (Ms-PL).
// Please see http://taskcardcreator.codeplex.com for details.
// All other rights reserved.

using System;
using System.Collections.Generic;
using System.Windows.Documents;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using ReportingFramework;
using WorkItemReportInterface;

namespace MicrosoftVisualStudioScrum10
{
  /// <summary>
  /// Interaction logic for MicrosoftVisualStudioScrum10Template.xaml
  /// </summary>
  public partial class MicrosoftVisualStudioScrum10Template : Report, IWorkItemReport
  {
    public MicrosoftVisualStudioScrum10Template()
    {
      InitializeComponent();
    }

    public FixedDocument Create(IEnumerable<WorkItem> data)
    {
      var rows = new List<object>();
      foreach (var workItem in data)
      {
        if (workItem.Type.Name == "Product Backlog Item")
        {
          rows.Add(new ProductBacklogItemCardRow(workItem));
        }
        else if (workItem.Type.Name == "Task")
        {
          rows.Add(new TaskCardRow(workItem));
        }
        else if (workItem.Type.Name == "Bug")
        {
          rows.Add(new BugCardRow(workItem));
        }
        else if (workItem.Type.Name == "Impediment")
        {
          rows.Add(new ImpedimentCardRow(workItem));
        }
        else
        {
          rows.Add(new UnknownCardRow(workItem));
        }
      }

      return GenerateReport(
          page => new PageInfo(page, DateTime.Now),
          rows
          );
    }

    public string TeamFoundationServerTemplate()
    {
      return "Microsoft Visual Studio Scrum 1.0";
    }

    /// <summary>
    /// This class becomes the data context for every page. It gives the page 
    /// access to the page number.
    /// </summary>
    public class PageInfo
    {
      public PageInfo(int pageNumber, DateTime reportDate)
      {
          PageNumber = pageNumber;
          ReportDate = reportDate;
      }

      public bool IsFirstPage { get { return PageNumber == 1; } }
      public int PageNumber { get; set; }
      public DateTime ReportDate { get; set; }
    }
  }
}